package com.mdxq.springboot03_junit.controller;

import com.mdxq.springboot03_junit.entity.Tea;
import com.mdxq.springboot03_junit.service.TeaService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author WanJl
 * @version 1.0
 * @title TeaController
 * @description
 * @create 2024/11/10
 */
@Controller
public class TeaController {

    @Resource
    private TeaService teaService;

    @RequestMapping("/tea/queryAll")
    @ResponseBody
    public List<Tea> queryAll() {
        List<Tea> teaList = teaService.queryAll();
        return teaList;
    }

    @RequestMapping("/tea/save")
    @ResponseBody
    public String save(@RequestBody Tea tea) {
        Integer i = teaService.save(tea);
        return "新增"+i+"条茶叶信息";
    }

    @RequestMapping("/tea/edit")
    @ResponseBody
    public String edit(@RequestBody Tea tea) {
        Integer i = teaService.edit(tea);
        return "修改"+i+"条茶叶信息";
    }

    @RequestMapping("/tea/remove")
    @ResponseBody
    public String remove(Integer id) {
        Integer i = teaService.remove(id);
        return "删除"+i+"条茶叶信息";
    }

    @RequestMapping("/tea/queryOne")
    @ResponseBody
    public Tea queryOne(Integer id) {
        return teaService.queryById(id);
    }
}
